package org.linlinjava.litemall.taobaoke.sdk;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.internal.util.StringUtils;
import com.taobao.api.request.*;
import com.taobao.api.response.*;

/**
 * @author haoting.wang
 * @date 2019-07-25 09:02
 **/
public class Demo {


    public static void main(String[] args) throws ApiException {

        test7();
    }


    public static void test10() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkDgNewuserOrderSumRequest req = new TbkDgNewuserOrderSumRequest();
        req.setPageSize(20L);
        req.setAdzoneId(109202950230L);
        req.setPageNo(1L);
        req.setSiteId(649700016L);
        req.setActivityId("200000_7");
        TbkDgNewuserOrderSumResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }


    public static void test9() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkDgOptimusMaterialRequest req = new TbkDgOptimusMaterialRequest();
        req.setAdzoneId(109202950230L);
        req.setMaterialId(9660L);
        TbkDgOptimusMaterialResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());


    }


    public static void test8() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkJuTqgGetRequest req = new TbkJuTqgGetRequest();
        req.setAdzoneId(109202950230L);
        req.setFields("click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time");
        req.setStartTime(StringUtils.parseDateTime("2019-07-25 09:00:00"));
        req.setEndTime(StringUtils.parseDateTime("2019-08-20 16:00:00"));
        req.setPageNo(1L);
        req.setPageSize(40L);
        TbkJuTqgGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void test7() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest();

     //   req.setQ("");
        req.setCat("50020485");
        req.setSort("total_sales_des");
        req.setEndPrice(2L);
        req.setNeedFreeShipment(true);

        req.setHasCoupon(true);
        req.setAdzoneId(109202950230L);

        TbkDgMaterialOptionalResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void test6() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
        req.setAdzoneId(109202950230L);
        req.setPlatform(1L);
//        req.setCat("16,18");
//        req.setPageSize(1L);
//        req.setQ("女装");
//        req.setPageNo(1L);
        TbkDgItemCouponGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void test5() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkUatmFavoritesGetRequest req = new TbkUatmFavoritesGetRequest();
        req.setPageNo(1L);
        req.setPageSize(20L);
        req.setFields("favorites_title,favorites_id,type");
        req.setType(1L);
        TbkUatmFavoritesGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void test4() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkUatmFavoritesItemGetRequest req = new TbkUatmFavoritesItemGetRequest();
        req.setPlatform(1L);
        req.setPageSize(20L);

        req.setAdzoneId(109202950230L);

        req.setUnid("3456");

        req.setFavoritesId(19644813L);


        req.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type");
        TbkUatmFavoritesItemGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void test3() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkCouponGetRequest req = new TbkCouponGetRequest();
        req.setMe("nfr%2BYTo2k1PX18gaNN%2BIPkIG2PadNYbBnwEsv6mRavWieOoOE3L9OdmbDSSyHbGxBAXjHpLKvZbL1320ML%2BCF5FRtW7N7yJ056Lgym4X01A%3D");
//        req.setItemId(20220241620L);
//        req.setActivityId("sdfwe3eefsdf");
        TbkCouponGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    /**
     * taobao.tbk.ju.tqg.get( 淘抢购api )
     *
     * @TODO
     */
    public static void test2() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkJuTqgGetRequest req = new TbkJuTqgGetRequest();
        req.setAdzoneId(123L);
        req.setFields("click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time");
        req.setStartTime(StringUtils.parseDateTime("2016-08-09 09:00:00"));
        req.setEndTime(StringUtils.parseDateTime("2016-08-09 16:00:00"));
        req.setPageNo(1L);
        req.setPageSize(40L);
        TbkJuTqgGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }


    /**
     * taobao.tbk.item.get
     * 淘宝客商品查询
     */
    public static void test1() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkItemGetRequest req = new TbkItemGetRequest();
        req.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
        req.setQ("女装");
//        req.setCat("16,18");
//        req.setItemloc("杭州");
        req.setSort("tk_rate_des");
//        req.setIsTmall(false);
//        req.setIsOverseas(false);
//        req.setStartPrice(10L);
//        req.setEndPrice(10L);
//        req.setStartTkRate(123L);
//        req.setEndTkRate(123L);
//        req.setPlatform(1L);
//        req.setPageNo(123L);
//        req.setPageSize(20L);
        TbkItemGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    /**
     * taobao.tbk.item.get
     * 淘宝客商品查询
     */
    public static void test() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "27712257", "274447c0dc6dae073e7a32291cf259b2");
        TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
        req.setNumIids("581687460548");
        req.setPlatform(1L);
   //     req.setIp("11.22.33.43");
        TbkItemInfoGetResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }
}
